select PRIORYEARCLOSEBALANCE,
NETPOSTING01,
BALANCE01
from
RD_GLMart.dbo.GL_Star_Facts
where BusinessUnitCode='         003'
and object='6650'

USE RD_DWCR
go
/****** Script for SelectTopNRows command from SSMS  ******/
SELECT TOP 100 [SourceID]
      ,[Source]
      ,[AccountID]
      ,[Century]
      ,[FiscalYear]
      ,[FiscalQuarter]
      ,[LedgerTypeCode]
      ,[SubLedger]
      ,[CompanyNumber]
      ,[PriorYearCloseBalance]
      ,[NetPosting01]
      ,[NetPosting02]
      ,[NetPosting03]
      ,[NetPosting04]
      ,[NetPosting05]
      ,[NetPosting06]
      ,[NetPosting07]
      ,[NetPosting08]
      ,[NetPosting09]
      ,[NetPosting10]
      ,[NetPosting11]
      ,[NetPosting12]
      ,[NetPosting13]
      ,[NetPosting14]
      ,[PriorYearEndNetPosting]
      ,[WeekToDateNetPosting]
      ,[OriginalBeginningBudget]
      ,[MemoBudgetChange]
      ,[PercentComplete]
      ,[MemoCommitmentChanges]
      ,[RequestedBudget]
      ,[ApprovedBudget]
      ,[BusinessUnitCode]
      ,[Object]
      ,[Subsidiary]
      ,[UserID]
      ,[ProgramID]
      ,[DateUpdated]
      ,[WorkStationID]
      ,[SubledgerType]
      ,[LastTimeUpdated]
      ,[CurrencyCodeFrom]
      ,[CurrencyCodeIn]
      ,[BalanceForward]
      ,[PurgeFlag]
      ,[NetDebitPosting01]
      ,[NetDebitPosting02]
      ,[NetDebitPosting03]
      ,[NetDebitPosting04]
      ,[NetDebitPosting05]
      ,[NetDebitPosting06]
      ,[NetDebitPosting07]
      ,[NetDebitPosting08]
      ,[NetDebitPosting09]
      ,[NetDebitPosting10]
      ,[NetDebitPosting11]
      ,[NetDebitPosting12]
      ,[NetDebitPosting13]
      ,[NetDebitPosting14]
      ,[InsertIndicator]
      ,[InsertDate]
      ,[ChangeIndicator]
      ,[ChangeDate]
      ,[DeleteIndicator]
      ,[DeleteDate]
      ,[PurgeDate]
  FROM [RD_DWCR].[dbo].[JDEGAAccountBalances]
where object ='6650  '
and LedgerTypeCode='AA'
and BusinessUnitCode='         003'



select 
 distinct(a11.BusinessUnitID) BUnitID,
 a11.GLDateID  CompanyDateID, a11.DocumentType  DocumentType,
 a12.Object  Object,
 
 a11.Amount  WJXBFS1
from GL_Star_FactsDetails a11
 inner join GL_Star_Facts a12
   on  (a11.AIDID = a12.AIDID and 
 a11.AccountID = a12.AccountID and 
 a11.BusinessUnitID = a12.BusinessUnitID and 
 a11.CompanyNumberID = a12.CompanyNumberID and 
 a11.LedgerTypeID = a12.LedgerTypeID and 
 a11.SubLedgerID = a12.SubLedgerID)
 inner join Common_Star_Account_Model a13
   on  (a11.AccountID = a13.AccountID)
 inner join Common_Star_BusinessUnit a14
   on  (a11.BusinessUnitID = a14.BusinessUnitID)
 inner join Common_Star_Dates a15
   on  (a11.GLDateID = a15.CompanyDateID)
where (a13.Object in ('6650  ')
 and a11.LedgerTypeCode = 'AA'
 and a15.Dates between CONVERT(datetime, '2010-03-01 09:44:00', 120) and CONVERT(datetime, '2010-03-31 09:44:00', 120))
 and a11.BusinessUnitID='         0031      '
 
 
 
 select a11.BusinessUnitID  BUnitID,
 max(a14.BusinessUnit)  BusinessUnit,
 max(a14.BusinessUnitCode)  BusinessUnitCode,
 a11.GLDateID  CompanyDateID,
 max(a15.Dates)  Dates,
 a11.DocumentType  DocumentType,
 a11.Object  Object,
 sum(a11.Amount)  WJXBFS1
from GL_Star_FactsDetails a11
 join GL_Star_Facts a12
   on  (a11.AIDID = a12.AIDID and 
 a11.AccountID = a12.AccountID and 
 a11.BusinessUnitID = a12.BusinessUnitID and 
 a11.CompanyNumberID = a12.CompanyNumberID and 
 a11.LedgerTypeID = a12.LedgerTypeID and 
 a11.SubLedgerID = a12.SubLedgerID)
 join Common_Star_Account_Model a13
   on  (a11.AccountID = a13.AccountID)
 join Common_Star_BusinessUnit a14
   on  (a11.BusinessUnitID = a14.BusinessUnitID)
 join Common_Star_Dates a15
   on  (a11.GLDateID = a15.CompanyDateID)
where (a13.Object in ('6650  ')
 and a11.LedgerTypeCode = 'AA'
  and a11.BusinessUnitID='         0021      '
 and a15.Dates between CONVERT(datetime, '2010-03-01 09:44:00', 120) and CONVERT(datetime, '2010-03-31 09:44:00', 120))
group by a11.BusinessUnitID,
 a11.GLDateID,
 a11.DocumentType,
 a11.Object
